import type { Metadata } from "next"; import Link from "next/link"; import { getLocale } from "@/lib/i18n/server"; import { href, t } from "@/lib/i18n"; import { logSearch, search, type SearchMode } from "@/lib/papers/search"; export const dynamic = "force-dynamic"; export async function generateMetadata(): Promise { const d = t(await getLocale()); return { title: d.search.title, description: d.search.lead, alternates: { canonical: "/search" } }; } export default async function SearchPage({ searchParams }: { searchParams: Promise<{ q?: string; mode?: string }> }) { const sp = await searchParams; const locale = await getLocale(); const d = t(locale); const q = (sp.q ?? "").trim(); const mode = (["hybrid", "lexical", "semantic"].includes(sp.mode ?? "") ? sp.mode : "hybrid") as SearchMode; const res = q ? await search(q, mode, 25) : null; if (res) await logSearch(q, res.mode, res.hits.length, locale, res.tookMs); return (

{d.search.title}

{d.search.lead}

{res && (

{res.hits.length} {res.hits.length === 1 ? d.papers.result : d.papers.results} · {d.search.took} {res.tookMs} ms · {res.semanticUsed ? d.search.semantic : d.search.lexical}{res.mode === "hybrid" && res.semanticUsed ? ` + ${d.search.lexical}` : ""}

{res.hits.length === 0 &&

{d.search.none}

}
    {res.hits.map((h) =>
  1. {h.identifier}{h.year ?? ""}{h.signals.map((s) => {d.search.fieldHit} {s})}

    {h.title}

    {h.authors.join(", ")}

    {h.snippets.map((s, i) =>

    )[^>]*>/g, "") }} />{s.page ? — p. {s.page} : null}

    )}
  2. )}
)}
); }